home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / components / jsconsole-clhandler.js < prev    next >
Text File  |  2006-05-08  |  6KB  |  157 lines

  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* vim:sw=4:sr:sta:et:sts: */
  3. /* ***** BEGIN LICENSE BLOCK *****
  4.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5.  *
  6.  * The contents of this file are subject to the Mozilla Public License Version
  7.  * 1.1 (the "License"); you may not use this file except in compliance with
  8.  * the License. You may obtain a copy of the License at
  9.  * http://www.mozilla.org/MPL/
  10.  *
  11.  * Software distributed under the License is distributed on an "AS IS" basis,
  12.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13.  * for the specific language governing rights and limitations under the
  14.  * License.
  15.  *
  16.  * The Original Code is mozilla.org code.
  17.  *
  18.  * The Initial Developer of the Original Code is
  19.  * Netscape Communications Corporation.
  20.  * Portions created by the Initial Developer are Copyright (C) 1999
  21.  * the Initial Developer. All Rights Reserved.
  22.  *
  23.  * Contributor(s):
  24.  *   Martijn Pieters <mj@digicool.com>
  25.  *   Benjamin Smedberg <benjamin@smedbergs.us>
  26.  *
  27.  * Alternatively, the contents of this file may be used under the terms of
  28.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  29.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  30.  * in which case the provisions of the GPL or the LGPL are applicable instead
  31.  * of those above. If you wish to allow use of your version of this file only
  32.  * under the terms of either the GPL or the LGPL, and not to allow others to
  33.  * use your version of this file under the terms of the MPL, indicate your
  34.  * decision by deleting the provisions above and replace them with the notice
  35.  * and other provisions required by the GPL or the LGPL. If you do not delete
  36.  * the provisions above, a recipient may use your version of this file under
  37.  * the terms of any one of the MPL, the GPL or the LGPL.
  38.  *
  39.  * ***** END LICENSE BLOCK ***** */
  40.  
  41. /*
  42.  * -jsconsole commandline handler; starts up the JavaScript console.
  43.  */
  44.  
  45. const nsISupports           = Components.interfaces.nsISupports;
  46. const nsICategoryManager    = Components.interfaces.nsICategoryManager;
  47. const nsIComponentRegistrar = Components.interfaces.nsIComponentRegistrar;
  48. const nsICommandLine        = Components.interfaces.nsICommandLine;
  49. const nsICommandLineHandler = Components.interfaces.nsICommandLineHandler;
  50. const nsIFactory            = Components.interfaces.nsIFactory;
  51. const nsIModule             = Components.interfaces.nsIModule;
  52. const nsIWindowWatcher      = Components.interfaces.nsIWindowWatcher;
  53.  
  54. /*
  55.  * Classes
  56.  */
  57.  
  58. const jsConsoleHandler = {
  59.     /* nsISupports */
  60.     QueryInterface : function clh_QI(iid) {
  61.         if (iid.equals(nsICommandLineHandler) ||
  62.             iid.equals(nsIFactory) ||
  63.             iid.equals(nsISupports))
  64.             return this;
  65.  
  66.         throw Components.results.NS_ERROR_NO_INTERFACE;
  67.     },
  68.  
  69.     /* nsICommandLineHandler */
  70.  
  71.     handle : function clh_handle(cmdLine) {
  72.         if (!cmdLine.handleFlag("jsconsole", false))
  73.             return;
  74.  
  75.         var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
  76.                                .getService(nsIWindowWatcher);
  77.         wwatch.openWindow(null, "chrome://global/content/console.xul", "_blank",
  78.                           "chrome,dialog=no,all", cmdLine);
  79.     },
  80.  
  81.     helpInfo : "  -jsconsole           Open the JavaScript console.\n",
  82.  
  83.     /* nsIFactory */
  84.  
  85.     createInstance : function clh_CI(outer, iid) {
  86.         if (outer != null)
  87.             throw Components.results.NS_ERROR_NO_AGGREGATION;
  88.  
  89.         return this.QueryInterface(iid);
  90.     },
  91.  
  92.     lockFactory : function clh_lock(lock) {
  93.         /* no-op */
  94.     }
  95. };
  96.  
  97. const clh_contractID = "@mozilla.org/toolkit/console-clh;1";
  98. const clh_CID = Components.ID("{2cd0c310-e127-44d0-88fc-4435c9ab4d4b}");
  99. const clh_category = "c-jsconsole";
  100.  
  101. const jsConsoleHandlerModule = {
  102.     /* nsISupports */
  103.  
  104.     QueryInterface : function mod_QI(iid) {
  105.         if (iid.equals(nsIModule) ||
  106.             iid.equals(nsISupports))
  107.             return this;
  108.  
  109.         throw Components.results.NS_ERROR_NO_INTERFACE;
  110.     },
  111.  
  112.     /* nsIModule */
  113.  
  114.     getClassObject : function mod_gch(compMgr, cid, iid) {
  115.         if (cid.equals(clh_CID))
  116.             return jsConsoleHandler.QueryInterface(iid);
  117.  
  118.         throw Components.results.NS_ERROR_NOT_REGISTERED;
  119.     },
  120.  
  121.     registerSelf : function mod_regself(compMgr, fileSpec, location, type) {
  122.         compMgr.QueryInterface(nsIComponentRegistrar);
  123.  
  124.         compMgr.registerFactoryLocation(clh_CID,
  125.                                         "jsConsoleHandler",
  126.                                         clh_contractID,
  127.                                         fileSpec,
  128.                                         location,
  129.                                         type);
  130.  
  131.         var catMan = Components.classes["@mozilla.org/categorymanager;1"]
  132.                                .getService(nsICategoryManager);
  133.         catMan.addCategoryEntry("command-line-handler",
  134.                                 clh_category,
  135.                                 clh_contractID, true, true);
  136.     },
  137.  
  138.     unregisterSelf : function mod_unreg(compMgr, location, type) {
  139.         compMgr.QueryInterface(nsIComponentRegistrar);
  140.  
  141.         compMgr.unregisterFactoryLocation(clh_CID, location);
  142.  
  143.         var catMan = Components.classes["@mozilla.org/categorymanager;1"]
  144.                                .getService(nsICategoryManager);
  145.         catMan.deleteCategoryEntry("command-line-handler", clh_category);
  146.     },
  147.  
  148.     canUnload : function (compMgr) {
  149.         return true;
  150.     }
  151. };
  152.  
  153. /* module initialisation */
  154. function NSGetModule(comMgr, fileSpec) {
  155.     return jsConsoleHandlerModule;
  156. }
  157.